package cn.wzut.edut.controller;

import cn.wzut.edut.pojo.JsonResult;
import cn.wzut.edut.pojo.RoleInfo;
import cn.wzut.edut.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 权限控制层
 */
@Validated
@RestController
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    PermissionService permissionService;

    /**
     * 添加权限赋予的角色请求
     * @param permissionId
     * @param roleIds
     * @return
     */
    @PostMapping("/add/role")
    public JsonResult addPermissionRole(@RequestParam(value = "permission_id") @NotNull String permissionId,
                                        @RequestParam(value = "role_id") @NotNull String[] roleIds){
        return new JsonResult(permissionService.addPermissionRole(permissionId, roleIds));
    }

    /**
     * 移除权限赋予的角色请求
     * @param permissionId
     * @param roleIds
     * @return
     */
    @PostMapping("/del/role")
    public JsonResult delPermissionRole(@RequestParam(value = "permission_id") @NotNull String permissionId,
                                        @RequestParam(value = "role_id") @NotNull String[] roleIds){
        return new JsonResult(permissionService.delPermissionRole(permissionId, roleIds));
    }

    /**
     * 获取权限列表请求
     * @return
     */
    @GetMapping("/get/list")
    public JsonResult getPermissionList(@RequestParam(value = "pagenum") @NotNull long current,
                                        @RequestParam(value = "pagesize") @NotNull long size){
        return new JsonResult(permissionService.getPermissionList(current, size));
    }







//    /**
//     * 获取权限分页列表请求
//     * @param request 请求头参数
//     * @return
//     */
//    @GetMapping("/perlist")
//    public JsonResult getPermissionByPage(HttpServletRequest request, long pagenum, long pagesize){
//        String token = request.getHeader("token"); // 获取请求头中的token
//        return new JsonResult(permissionService.getPermissionList(token, pagenum, pagesize));
//    }
//
//    /**
//     * 查询权限请求
//     * @param request 请求头参数
//     * @return
//     */
//    @GetMapping("/querypre")
//    public JsonResult getPermissionByName(HttpServletRequest request, long pagenum, long pagesize, String permissionname){
//        String token = request.getHeader("token"); // 获取请求头中的token
//        return new JsonResult(permissionService.getPermissionListByName(token, pagenum, pagesize, permissionname));
//    }
//
//    /**
//     * 查询当前权限赋予的角色请求
//     * @param request 请求头参数
//     * @return
//     */
//    @GetMapping("/query")
//    public JsonResult getRoleByPermission(HttpServletRequest request, String permissionid, long pagenum, long pagesize){
//        String token = request.getHeader("token"); // 获取请求头中的token
//        return new JsonResult(permissionService.getRoleByPermission(token, pagenum, pagesize, permissionid));
//    }
//
//    /**
//     * 更改权限赋予请求
//     * @param request 请求头参数
//     * @return
//     */
//    @PostMapping("/update")
//    public JsonResult updatePermission(HttpServletRequest request, String permissionID, String del_roleid[], String add_roleid[]){
//        String token = request.getHeader("token");
//        return new JsonResult();
//    }

}
